package com.spzx.product;

import com.spzx.common.security.annotation.EnableCustomConfig;
import com.spzx.common.security.annotation.EnableRyFeignClients;
import com.spzx.product.domain.ProductSku;
import com.spzx.product.mapper.ProductSkuMapper;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;

/**
 * 商品模块
 *
 * @author spzx
 */
@EnableCustomConfig//开启自定义配置
@EnableRyFeignClients//开启Feign客户端的自动配置
@SpringBootApplication//开启springboot自动配置
//@ComponentScan(basePackages = {"com.spzx.user.api"})
public class SpzxProductApplication implements CommandLineRunner {
    public static void main(String[] args) {

        SpringApplication.run(SpzxProductApplication.class, args);
        System.out.println("(♥◠‿◠)ﾉﾞ  系统模块启动成功   ლ(´ڡ`ლ)ﾞ  \n" +
                " .-------.       ____     __        \n" +
                " |  _ _   \\      \\   \\   /  /    \n" +
                " | ( ' )  |       \\  _. /  '       \n" +
                " |(_ o _) /        _( )_ .'         \n" +
                " | (_,_).' __  ___(_ o _)'          \n" +
                " |  |\\ \\  |  ||   |(_,_)'         \n" +
                " |  | \\ `'   /|   `-'  /           \n" +
                " |  |  \\    /  \\      /           \n" +
                " ''-'   `'-'    `-..-'              ");
    }

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private ProductSkuMapper productSkuMapper;

    // 实现CommandLineRunner接口，在项目启动完成后执行该方法
    @Override
    public void run(String... args) throws Exception {
        String key = "product:sku:data";
        //查询mysql里面的商品shuId
        List<ProductSku> productSkuList = productSkuMapper.selectList(null);
        productSkuList.forEach(productSku -> {
            //将商品sku信息存入redis
            redisTemplate.opsForValue().setBit(key, productSku.getId(), true);
        });
    }
}
